package com.example.livingadminmaster.common;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Date;

@Component
public class MyMetaObjectHandle implements MetaObjectHandler {
    /**
     * 在插入的时候响应相关操作
     *
     * @param metaObject
     */
    @Override
    public void insertFill(MetaObject metaObject) {
/**
 * 大意是将当前的时间赋值给字段名  也就是参数2 赋值给参数1 metaObject 可理解为当前传入对象
 * 人话:就是给当前传入对象赋值
 */
        this.strictInsertFill(metaObject,"createTime", LocalDateTime.class,LocalDateTime.now());
        this.strictInsertFill(metaObject,"updateTime", LocalDateTime.class,LocalDateTime.now());
//        this.strictInsertFill(metaObject,"createTime", LocalDateTime.class,LocalDateTime.now());
//        this.strictInsertFill(metaObject,"updateTime", LocalDateTime.class,LocalDateTime.now());
    }

    /**
     * 在插入的时候响应相关操作
     *
     * @param metaObject
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject,"updateTime", LocalDateTime.class,LocalDateTime.now());
//        this.strictInsertFill(metaObject,"updateTime", LocalDateTime.class,LocalDateTime.now());
    }
}
